home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 419_01 / odmg10 / util / scripts / lndir.sh < prev    next >
Encoding:
Linux/UNIX/POSIX Shell Script  |  1993-09-09  |  1.9 KB  |  98 lines

  1. #! /bin/sh
  2.  
  3. # lndir - create shadow link tree
  4. #
  5. # Time stamp <89/11/28 18:56:54 gildea>
  6. # By Stephen Gildea <gildea@bbn.com> based on
  7. #  XConsortium: lndir.sh,v 1.1 88/10/20 17:37:16 jim Exp
  8. #
  9. # Used to create a copy of the a directory tree that has links for all non-
  10. # directories (except those named RCS).  If you are building the distribution
  11. # on more than one machine, you should use this script.
  12. #
  13. # If your master sources are located in /usr/local/src/X and you would like
  14. # your link tree to be in /usr/local/src/new-X, do the following:
  15. #
  16. #     %  mkdir /usr/local/src/new-X
  17. #    %  cd /usr/local/src/new-X
  18. #     %  lndir ../X
  19. #
  20. # Note: does not link files beginning with "."  Is this a bug or a feature?
  21. #
  22. # Improvements over R3 version:
  23. #   Allows the fromdir to be relative: usually you want to say "../dist"
  24. #   The name is relative to the todir, not the current directory.
  25. #
  26. # Bugs in R3 version fixed:
  27. #   Do "pwd" command *after* "cd $DIRTO".
  28. #   Don't try to link directories, avoiding error message "<dir> exists".
  29. #   Barf with Usage message if either DIRFROM *or* DIRTO is not a directory.
  30.  
  31. USAGE="Usage: $0 fromdir [todir]"
  32.  
  33. if [ $# -lt 1 -o $# -gt 2 ]
  34. then
  35.     echo "$USAGE"
  36.     exit 1
  37. fi
  38.  
  39. DIRFROM=$1
  40.  
  41. if [ $# -eq 2 ];
  42. then
  43.     DIRTO=$2
  44. else
  45.     DIRTO=.
  46. fi
  47.  
  48. if [ ! -d $DIRTO ]
  49. then
  50.     echo "$0: $DIRTO is not a directory"
  51.     echo "$USAGE"
  52.     exit 2
  53. fi
  54.  
  55. cd $DIRTO
  56.  
  57. if [ ! -d $DIRFROM ]
  58. then
  59.     echo "$0: $DIRFROM is not a directory"
  60.     echo "$USAGE"
  61.     exit 2
  62. fi
  63.  
  64. pwd=`pwd`
  65.  
  66. if [ `(cd $DIRFROM; pwd)` = $pwd ]
  67. then
  68.     echo "$pwd: FROM and TO are identical!"
  69.     exit 1
  70. fi
  71.  
  72. for file in `ls $DIRFROM`
  73. do
  74.     if [ ! -d $DIRFROM/$file ]
  75.     then
  76.         ln -s $DIRFROM/$file .
  77.     else
  78.         if [ $file != RCS ]
  79.         then
  80.             echo $file:
  81.             mkdir $file
  82.             (cd $file
  83.              pwd=`pwd`
  84.              case "$DIRFROM" in
  85.                  /*) ;;
  86.                  *)  DIRFROM=../$DIRFROM ;;
  87.              esac
  88.              if [ `(cd $DIRFROM/$file; pwd)` = $pwd ]
  89.              then
  90.                 echo "$pwd: FROM and TO are identical!"
  91.                 exit 1
  92.              fi
  93.              $0 $DIRFROM/$file
  94.             )
  95.         fi
  96.     fi
  97. done
  98.